package com.shopoo.oauth.infrastructure.repository;

import java.util.List;

import javax.annotation.Resource;

import com.shopoo.oauth.domain.repository.PowerCacheRepository;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

/**
 * @Description: 权限缓存服务
 * @Auther: limy66
 * @Date: 2021/05/12/10:54
 */
@Repository
public class PowerCacheRepositoryImpl implements PowerCacheRepository {

    @Resource
    private RedisTemplate redisTemplate;

    @Value("${redis.shopoo.oauth2.roleMenusKey}")
    private String roleMenusKey;

    @Override
    public void removeAllRoleMenus() {
        redisTemplate.delete(roleMenusKey);
    }

    @Override
    public void cacheAllRoleMenus(List<String> list) {
        if (list == null || list.isEmpty()) {
            return;
        }
        redisTemplate.opsForList().leftPushAll(roleMenusKey, list);
    }
}
